package com.ymatou.iapi.sellercs.testcase;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.sellercs.parameter.GetMessageListAndSessionByTimelineBean;
import com.ymatou.iapi.sellercs.parameter.MessageResp;
import com.ymatou.iapi.sellercs.parameter.MessageSessionResp;
import com.ymatou.iapi.sellercs.parameter.SendMessageBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageWithAttachBean;
import com.ymatou.iapi.sellercs.service.GetMessageListAndSessionByTimelineCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.resp.UserInfo2;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.model.YmtQueuesession;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*根据时间获取私信列表含会话
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMessageListAndSessionByTimeline{
	private static GetMessageListAndSessionByTimelineBean getmessagelistandsessionbytimelineBean;
	private static GetMessageListAndSessionByTimelineCall getmessagelistandsessionbytimelineCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	private static ImDefaultWapper im;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据时间获取私信列表含会话");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		getmessagelistandsessionbytimelineBean=new GetMessageListAndSessionByTimelineBean();
		getmessagelistandsessionbytimelineCall=new GetMessageListAndSessionByTimelineCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
		im=new ImDefaultWapper();
		SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmessagelistandsessionbytimelineCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_001() {
		Logger.start(true,"根据时间获取私信列表含会话成功,inNew:false,IsNotClearUnReadCount:false,LongPostTime=0");
		try {
			//IsNew=true获取时间线之后的数据 
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			int unread=SellerCSIMCallService.getUnReadNum(sellerId);
			
			SellerCSIMCallService.SetMessageSessionImportant(userId, sellerId);
			Thread.sleep(1000);
			getmessagelistandsessionbytimelineBean.setCSId(sellerId);
			getmessagelistandsessionbytimelineBean.setToUserId(userId);
			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("No");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			
			MessageSessionResp session = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageSession();
			JUserWapper JUserWapper=new JUserWapper();
			String fromurl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(fromurl==null?JUserCallService.defaultSellerImg:fromurl,session.getFromUserLogo(),"验证FromUserLogo");
			String tourl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(tourl==null?JUserCallService.defaultImg:tourl,session.getToUserLogo(),"验证ToUserLogo");
			
			String fromname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLoginId();
			Logger.verifyEquals(fromname,session.getFromUserName(),"验证FromUserName");
			
			String toname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLoginId();
			Logger.verifyEquals(toname,session.getToUserName(),"验证toname");
			
			Logger.verifyNotNull(session.getUserSessionId(),"验证msgId");
			List<Map> list =im.selectTotalCount(userId, sellerId);
			int isimp=(int) list.get(0).get("IsImportant");
			Logger.verifyEquals(isimp==1,session.getIsImportant(),"是否重要消息");
			
			List<MessageResp> mlist = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList();
			//[{"MessageId":"24716664_24635724_200809","PostTime":"2018-10-15T11:30:57","LongPostTime":1539574257950,"MsgFromId":24716664,"MsgToId":24635724,"Message":"connect","MsgFrom":"autotestP26i64z","MsgTo":"autotest1","SessionNumber":"20181015113057_24635724_24716664","MessageAttachList":[]}]

			Logger.verifyEquals(1, mlist.size(), "验证记录数");
			Logger.verifyNotNull(mlist.get(0).getMessageId(), "验证msgid");
			Logger.verifyEquals(getmessagelistandsessionbytimelineBean.getCSId(),mlist.get(0).getCsId(), "验证csid");
			Logger.verifyEquals(JUserCallService.GetUserInfo(getmessagelistandsessionbytimelineBean.getCSId()).getLoginId(),mlist.get(0).getCsName(), "验证CSName");
			Logger.verifyEquals(sendmessageBean.getFromUserId(),mlist.get(0).getMsgFromId(), "验证msgfromid");
			Logger.verifyEquals(sendmessageBean.getToUserId(),mlist.get(0).getMsgToId(), "验证msgtoid");
			Logger.verifyEquals(sendmessageBean.getMessage(),mlist.get(0).getMessage(), "验证Message");
			
			Logger.verifyEquals(JUserCallService.GetUserInfo(sendmessageBean.getFromUserId()).getLoginId(),mlist.get(0).getMsgFrom(), "验证msgfrom");
			Logger.verifyEquals(JUserCallService.GetUserInfo(sendmessageBean.getToUserId()).getLoginId(),mlist.get(0).getMsgTo(), "验证msgto");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_002() {
		Logger.start(true,"不输入csid根据from、to查询");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			int unread=SellerCSIMCallService.getUnReadNum(sellerId);
			
			SellerCSIMCallService.SetMessageSessionImportant(userId, sellerId);
			Thread.sleep(1000);
//			getmessagelistandsessionbytimelineBean.setCSId(sellerId);
			getmessagelistandsessionbytimelineBean.setToUserId(userId);
			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("No");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			Logger.verifyEquals(1, getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList().size(), "没有数据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_003() {
		Logger.start(true,"不输入Fromuserid和ToUserId");
		try {
			//这里为了兼容旧格式会返回一些格式
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			int unread=SellerCSIMCallService.getUnReadNum(sellerId);
			
			SellerCSIMCallService.SetMessageSessionImportant(userId, sellerId);
			Thread.sleep(1000);
			getmessagelistandsessionbytimelineBean.setCSId(sellerId);
//			getmessagelistandsessionbytimelineBean.setToUserId(userId);
//			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("No");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
//			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			Logger.verifyEquals(null, getmessagelistandsessionbytimelineCall.getResult(), "没有数据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_004() {
		Logger.start(true,"根据时间获取私信列表含会话成功,inNew:true获取比时间轴更新的记录");
		try {
			//IsNew=true获取时间线之后的数据 
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			int unread=SellerCSIMCallService.getUnReadNum(sellerId);
			
			SellerCSIMCallService.SetMessageSessionImportant(userId, sellerId);
			Thread.sleep(1000);
			getmessagelistandsessionbytimelineBean.setCSId(sellerId);
			getmessagelistandsessionbytimelineBean.setToUserId(userId);
			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("Yes");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			Logger.verifyEquals(0, getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList().size(), "没有数据");
//			MessageSessionResp session = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageSession();
//			JUserWapper JUserWapper=new JUserWapper();
//			String fromurl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLogoUrl();
//			Logger.verifyEquals(fromurl==null?JUserCallService.defaultImg:fromurl,session.getFromUserLogo(),"验证FromUserLogo");
//			String tourl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLogoUrl();
//			Logger.verifyEquals(tourl==null?JUserCallService.defaultImg:tourl,session.getToUserLogo(),"验证ToUserLogo");
//			
//			String fromname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLoginId();
//			Logger.verifyEquals(fromname,session.getFromUserName(),"验证FromUserName");
//			
//			String toname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLoginId();
//			Logger.verifyEquals(toname,session.getToUserName(),"验证toname");
//			
//			Logger.verifyNotNull(session.getUserSessionId(),"验证msgId");
//			List<Map> list =im.selectTotalCount(userId, sellerId);
//			int isimp=(int) list.get(0).get("IsImportant");
//			Logger.verifyEquals(isimp==1,session.getIsImportant(),"是否重要消息");
//			
//			List<MessageResp> mlist = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList();
//			//[{"MessageId":"24716664_24635724_200809","PostTime":"2018-10-15T11:30:57","LongPostTime":1539574257950,"MsgFromId":24716664,"MsgToId":24635724,"Message":"connect","MsgFrom":"autotestP26i64z","MsgTo":"autotest1","SessionNumber":"20181015113057_24635724_24716664","MessageAttachList":[]}]
//
//			Logger.verifyEquals(1, mlist.size(), "验证记录数");
//			Logger.verifyNotNull(mlist.get(0).getMessageId(), "验证msgid");
//			Logger.verifyEquals(getmessagelistandsessionbytimelineBean.getCSId(),mlist.get(0).getCsId(), "验证csid");
//			Logger.verifyEquals(JUserCallService.GetUserInfo(getmessagelistandsessionbytimelineBean.getCSId()).getLoginId(),mlist.get(0).getCsName(), "验证CSName");
//			Logger.verifyEquals(sendmessageBean.getFromUserId(),mlist.get(0).getMsgFromId(), "验证msgfromid");
//			Logger.verifyEquals(sendmessageBean.getToUserId(),mlist.get(0).getMsgToId(), "验证msgtoid");
//			Logger.verifyEquals(sendmessageBean.getMessage(),mlist.get(0).getMessage(), "验证Message");
//			
//			Logger.verifyEquals(JUserCallService.GetUserInfo(sendmessageBean.getFromUserId()).getLoginId(),mlist.get(0).getMsgFrom(), "验证msgfrom");
//			Logger.verifyEquals(JUserCallService.GetUserInfo(sendmessageBean.getToUserId()).getLoginId(),mlist.get(0).getMsgTo(), "验证msgto");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//不存在IsNotClearUnReadCount:true,不更新未读 im.iapi必然更新
	public void Tc_GetMessageListAndSessionByTimeline_005() {
		Logger.start(true,"根据时间获取私信列表含会话成功,IsNotClearUnReadCount:true,不更新未读");
		try {
			org.junit.Assert.fail();
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_006() {
		Logger.start(true,"获取子账号会话成功");
		try {
			//IsNew=true获取时间线之后的数据 
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(zsellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			sendmessageBean.setCSId(zsellerId);
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			
			SellerCSIMCallService.SetMessageSessionImportant(userId, zsellerId);
			Thread.sleep(1000);
			getmessagelistandsessionbytimelineBean.setCSId(zsellerId);
			getmessagelistandsessionbytimelineBean.setToUserId(userId);
			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("No");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			
			MessageSessionResp session = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageSession();
			JUserWapper JUserWapper=new JUserWapper();
			String fromurl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(fromurl==null?JUserCallService.defaultSellerImg:fromurl,session.getFromUserLogo(),"验证FromUserLogo");
			String tourl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(tourl==null?JUserCallService.defaultImg:tourl,session.getToUserLogo(),"验证ToUserLogo");
			
			String fromname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLoginId();
			Logger.verifyEquals(fromname,session.getFromUserName(),"验证FromUserName");
			
			String toname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLoginId();
			Logger.verifyEquals(toname,session.getToUserName(),"验证toname");
			
			Logger.verifyNotNull(session.getUserSessionId(),"验证msgId");
			List<Map> list =im.selectTotalCount(userId, zsellerId);
			int isimp=(int) list.get(0).get("IsImportant");
			Logger.verifyEquals(isimp==1,session.getIsImportant(),"是否重要消息");
			
			List<MessageResp> mlist = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList();
			//[{"MessageId":"24716664_24635724_200809","PostTime":"2018-10-15T11:30:57","LongPostTime":1539574257950,"MsgFromId":24716664,"MsgToId":24635724,"Message":"connect","MsgFrom":"autotestP26i64z","MsgTo":"autotest1","SessionNumber":"20181015113057_24635724_24716664","MessageAttachList":[]}]

			Logger.verifyEquals(1, mlist.size(), "验证记录数");
			Logger.verifyNotNull(mlist.get(0).getMessageId(), "验证msgid");
			Logger.verifyEquals(getmessagelistandsessionbytimelineBean.getCSId(),mlist.get(0).getCsId(), "验证csid");
			Logger.verifyEquals(JUserCallService.GetUserInfo(getmessagelistandsessionbytimelineBean.getCSId()).getLoginId(),mlist.get(0).getCsName(), "验证CSName");
			Logger.verifyEquals(sendmessageBean.getFromUserId(),mlist.get(0).getMsgFromId(), "验证msgfromid");
			Logger.verifyEquals(sendmessageBean.getToUserId(),mlist.get(0).getMsgToId(), "验证msgtoid");
			Logger.verifyEquals(sendmessageBean.getMessage(),mlist.get(0).getMessage(), "验证Message");
			
			Logger.verifyEquals(JUserCallService.GetUserInfo(sendmessageBean.getFromUserId()).getLoginId(),mlist.get(0).getMsgFrom(), "验证msgfrom");
			Logger.verifyEquals(JUserCallService.GetUserInfo(sendmessageBean.getToUserId()).getLoginId(),mlist.get(0).getMsgTo(), "验证msgto");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_007() {
		Logger.start(true,"获取带附件会话成功");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageWithAttachBean smwa = SellerCSIMCallService.SendMessageWithAttach(userId, sellerId);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(1000);
			getmessagelistandsessionbytimelineBean.setCSId(sellerId);
			getmessagelistandsessionbytimelineBean.setToUserId(userId);
			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("No");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			
			MessageSessionResp session = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageSession();
			JUserWapper JUserWapper=new JUserWapper();
			String fromurl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(fromurl==null?JUserCallService.defaultSellerImg:fromurl,session.getFromUserLogo(),"验证FromUserLogo");
			String tourl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(tourl==null?JUserCallService.defaultImg:tourl,session.getToUserLogo(),"验证ToUserLogo");
			
			String fromname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLoginId();
			Logger.verifyEquals(fromname,session.getFromUserName(),"验证FromUserName");
			
			String toname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLoginId();
			Logger.verifyEquals(toname,session.getToUserName(),"验证toname");
			
			Logger.verifyNotNull(session.getUserSessionId(),"验证msgId");
			List<Map> list =im.selectTotalCount(userId, sellerId);
			int isimp=(int) list.get(0).get("IsImportant");
			Logger.verifyEquals(isimp==1,session.getIsImportant(),"是否重要消息");
			
			List<MessageResp> mlist = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList();
			//[{"MessageId":"24716664_24635724_200809","PostTime":"2018-10-15T11:30:57","LongPostTime":1539574257950,"MsgFromId":24716664,"MsgToId":24635724,"Message":"connect","MsgFrom":"autotestP26i64z","MsgTo":"autotest1","SessionNumber":"20181015113057_24635724_24716664","MessageAttachList":[]}]

			Logger.verifyEquals(1, mlist.size(), "验证记录数");
			Logger.verifyNotNull(mlist.get(0).getMessageId(), "验证msgid");
			Logger.verifyEquals(getmessagelistandsessionbytimelineBean.getCSId(),mlist.get(0).getCsId(), "验证csid");
			Logger.verifyEquals(JUserCallService.GetUserInfo(getmessagelistandsessionbytimelineBean.getCSId()).getLoginId(),mlist.get(0).getCsName(), "验证CSName");
			Logger.verifyEquals(smwa.getMasterCSId(),mlist.get(0).getMsgFromId(), "验证msgfromid");
			Logger.verifyEquals(smwa.getUserId(),mlist.get(0).getMsgToId(), "验证msgtoid");
			Logger.verifyEquals(smwa.getMessage(),mlist.get(0).getMessage(), "验证Message");
			
			Logger.verifyEquals(JUserCallService.GetUserInfo(smwa.getMasterCSId()).getLoginId(),mlist.get(0).getMsgFrom(), "验证msgfrom");
			Logger.verifyEquals(JUserCallService.GetUserInfo(smwa.getUserId()).getLoginId(),mlist.get(0).getMsgTo(), "验证msgto");
			
			Logger.verifyEquals(smwa.getMessageAttachList().size(),mlist.get(0).getMessageAttachList().size(),"验证附件列表");
			Logger.debug("send:"+FormatUtil.beanToGSONString(smwa.getMessageAttachList()));
			Logger.debug("rt"+FormatUtil.beanToGSONString(mlist.get(0).getMessageAttachList()));
			List<String> contentlist = smwa.getMessageAttachList().stream().map(map->{return map.getContent();}).collect(Collectors.toList());
			List<Integer> typelist = smwa.getMessageAttachList().stream().map(map->{return map.getType();}).collect(Collectors.toList());
			mlist.get(0).getMessageAttachList().forEach(ma->{
				Logger.verifyEquals(true, typelist.contains(ma.getType()), "验证type");
				Logger.verifyEquals(true, contentlist.contains(ma.getContent()), "验证content");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMessageListAndSessionByTimeline_009() {
		Logger.start(true,"根据时间获取私信列表含会话成功,消息包含导流信息");
		try {
			String fpath = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "noymt.jpg";
			TestDataManager.CreateMatrixFile("http://u.wechat.com/1.jpg", fpath);
			String turl=TestDataManager.UploadFile(fpath);
			//IsNew=true获取时间线之后的数据 
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
//			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "[img]"+turl+"[/img]");
			SellerCSIMCallService.SellerSendMessage(sellerId, userId, "[img]"+turl+"[/img]");
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			int unread=SellerCSIMCallService.getUnReadNum(sellerId);
			
			SellerCSIMCallService.SetMessageSessionImportant(userId, sellerId);
			Thread.sleep(1000);
			getmessagelistandsessionbytimelineBean.setCSId(sellerId);
			getmessagelistandsessionbytimelineBean.setToUserId(userId);
			getmessagelistandsessionbytimelineBean.setFromUserId(sellerId);
			getmessagelistandsessionbytimelineBean.setLongPostTime(0l);
			getmessagelistandsessionbytimelineBean.setIsNew("No");
			getmessagelistandsessionbytimelineBean.setMessageCount(20);
			getmessagelistandsessionbytimelineCall.setData(getmessagelistandsessionbytimelineBean);
			getmessagelistandsessionbytimelineCall.callService();			
			Logger.verifyIsContains("200", getmessagelistandsessionbytimelineCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getmessagelistandsessionbytimelineCall.getResult()));
			
			MessageSessionResp session = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageSession();
			JUserWapper JUserWapper=new JUserWapper();
			String fromurl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(fromurl==null?JUserCallService.defaultSellerImg:fromurl,session.getFromUserLogo(),"验证FromUserLogo");
			String tourl=JUserWapper.selectUserinfoexByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLogoUrl();
			Logger.verifyEquals(tourl==null?JUserCallService.defaultImg:tourl,session.getToUserLogo(),"验证ToUserLogo");
			
			String fromname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getFromUserId()).get(0).getLoginId();
			Logger.verifyEquals(fromname,session.getFromUserName(),"验证FromUserName");
			
			String toname=JUserWapper.selectUserinfoByUid(getmessagelistandsessionbytimelineBean.getToUserId()).get(0).getLoginId();
			Logger.verifyEquals(toname,session.getToUserName(),"验证toname");
			
			Logger.verifyNotNull(session.getUserSessionId(),"验证msgId");
			List<Map> list =im.selectTotalCount(userId, sellerId);
			int isimp=(int) list.get(0).get("IsImportant");
			Logger.verifyEquals(isimp==1,session.getIsImportant(),"是否重要消息");
			
			List<MessageResp> mlist = getmessagelistandsessionbytimelineCall.getResult().getYmtMessageList();
			//[{"MessageId":"24716664_24635724_200809","PostTime":"2018-10-15T11:30:57","LongPostTime":1539574257950,"MsgFromId":24716664,"MsgToId":24635724,"Message":"connect","MsgFrom":"autotestP26i64z","MsgTo":"autotest1","SessionNumber":"20181015113057_24635724_24716664","MessageAttachList":[]}]

			Logger.verifyEquals(1, mlist.size(), "验证记录数");
			Logger.verifyNotNull(mlist.get(0).getMessageId(), "验证msgid");
			Logger.verifyEquals(getmessagelistandsessionbytimelineBean.getCSId(),mlist.get(0).getCsId(), "验证csid");
			Logger.verifyEquals(JUserCallService.GetUserInfo(getmessagelistandsessionbytimelineBean.getCSId()).getLoginId(),mlist.get(0).getCsName(), "验证CSName");
			Logger.verifyEquals(2,mlist.get(0).getMessageAttachList().get(0).getType(),"验证type");
			Logger.verifyIsContains("屏蔽",mlist.get(0).getMessageAttachList().get(0).getContent(),"验证Content");
			Logger.verifyEquals(true,mlist.get(0).getIsCancel(),"验证IsCancel");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}